<?php
declare (strict_types = 1);

namespace app\controller;


use app\common\model\Nicknames;
use think\facade\Request;

class AdminNickname extends AdminInit
{
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        if(Request::isAjax()){
            $d = \request()->param();
            $nicknames = $d["nicknames"];
            $nicknames = explode("\n",$nicknames);
            $arr = [];
            foreach ($nicknames as $v){
                if($v){
                    $temp["nickname"] = $v;
                    $arr[] = $temp;
                }
            }

            $mod = new Nicknames();
            $res = $mod->saveAll($arr);
            if($res){
                return json(["code"=>200,"msg"=>"导入成功"]);
            }else{
                return json(["code"=>400,"msg"=>"导入失败"]);
            }
        }

        return  view();
    }

}
